package com.school.movie.business.web.controller;

import com.school.movie.business.web.model.vo.*;
import com.school.movie.common.utils.ContextUtils;
import com.school.movie.common.bean.PageBean;
import com.school.movie.service.imp.MovieServiceImpl;
import com.school.movie.service.imp.OrderServiceImpl;
import com.school.movie.service.imp.PlanServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/report")
public class ReportController {

    @Autowired
    PlanServiceImp planService;
    @Autowired
    OrderServiceImpl orderService;
    @Autowired
    MovieServiceImpl movieService;

    //票房统计
    @RequestMapping("/movieReport")
    public String movieReport(PlanVo plan, HttpServletRequest request, HttpSession session, PageBean pager, ModelMap map) {
        if (plan == null || plan.getMovieName() == null) {
            if (session.getAttribute("planRep") != null) {
                plan = (PlanVo) session.getAttribute("planRep");
            }
        } else {
            session.setAttribute("planRep", plan);
        }
        List<MovieVo> movieList = movieService.findMovieListByPlayType();
        List<OrderVo> orderList = orderService.movieRep(plan, pager);
        pager.setData(orderList);
        map.addAttribute("movieList", movieList);
        map.addAttribute("pager", pager);
        map.addAttribute("plan", plan);
        return "repMovie";
    }

    //影院统计
    @RequestMapping("/agentReport")
    public String agentReport(PlanVo plan, HttpServletRequest request, HttpSession session, PageBean pager, ModelMap map) {
        Manager mgr = ContextUtils.getManagerInfo();
        if (plan == null || plan.getAgentName() == null) {
            if (session.getAttribute("planRep") != null) {
                plan = (PlanVo) session.getAttribute("planRep");
            }
        } else {
            session.setAttribute("planRep", plan);
        }
        int agentId = 0;
        if (mgr.getManagerType() != 3) {
            agentId = mgr.getAgentId();
        }
        List<AgentInfo> agentList = orderService.agentList(agentId);
        List<OrderVo> orderList = orderService.agentRep(plan, pager);
        pager.setData(orderList);
        map.addAttribute("agentList", agentList);
        map.addAttribute("pager", pager);
        map.addAttribute("plan", plan);
        return "repAgent";
    }

    //影厅统计
    @RequestMapping("/hallReport")
    public String hallReport(PlanVo plan, HttpServletRequest request, HttpSession session, PageBean pager, ModelMap map) {
        Manager mgr = ContextUtils.getManagerInfo();
        if (plan == null || plan.getAgentName() == null) {
            if (session.getAttribute("planRep") != null) {
                plan = (PlanVo) session.getAttribute("planRep");
            }
        } else {
            session.setAttribute("planRep", plan);
        }
        int agentId = 0;
        if (mgr.getManagerType() != 3) {
            agentId = mgr.getAgentId();
        }
        List<AgentInfo> agentList = orderService.agentList(agentId);
        List<OrderVo> orderList = orderService.hallRep(plan, pager);
        pager.setData(orderList);
        map.addAttribute("agentList", agentList);
        map.addAttribute("pager", pager);
        map.addAttribute("plan", plan);
        return "repHall";
    }

}
